package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.IpAddress;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeDefaultAddress implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        //*WT,868976030203477,V4,S24,161841,112.74.176.68:9098,161744,A,2250.2269,N,11391.6159,E,0.11,122,170721,FFFFDFFF#
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[4];
        String ip= split[5].split(":")[0];
        String port = split[5].split(":")[1];
        String time = split[6];//指令返回信息的时间
        String lat = split[8];
        String lng = split[10];
        String speed = split[12];
        String orientation = split[13];
        String date = split[14];
        String deviceStatus = split[15];
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        IpAddress ipAddress = new IpAddress();
        ipAddress.setImei(imei);
        ipAddress.setCommandNumber(commandNumber);
        ipAddress.setDeviceDate(date);
        ipAddress.setDeviceStatus(deviceStatus);
        ipAddress.setDeviceTime(time);
        ipAddress.setIp(ip);
        ipAddress.setPort(port);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        ipAddress.setLocationData(mqLocationData);
        return structureMessage(Constants.REPLY,Constants.CMD_DEFAULT_ADDRESS,false,"",ipAddress);
    }
}
